package com.glhtgyxy.biyesheji.Controller;

import com.glhtgyxy.biyesheji.Pojo.evaluate;
import com.glhtgyxy.biyesheji.Service.evaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;

@Controller
@RequestMapping("evaluate")
@CrossOrigin(origins = "*")
public class evaluateController {

    @Autowired
    evaluateService service;

    @ResponseBody
    @RequestMapping("merchant")
    public ArrayList<evaluate> evaluateMerchant(){
        System.out.println("所有评价查询中");
        ArrayList<evaluate> evaluates = service.findAllEvaluateMerchant();
        System.out.println("查询结束，返回："+evaluates);
        return evaluates;
    }

    @ResponseBody
    @RequestMapping("deletemerchant/{id}")
    public boolean deleteMerchant(@PathVariable int id){
        System.out.println("删除评价中,id:"+id);
        boolean evaluates =true;
        evaluates = service.deleteMerchant(id);
        System.out.println("删除结束，返回："+evaluates);
        return evaluates;
    }

    @ResponseBody
    @RequestMapping("updatemerchanteva/{id}/{star}/{evaluate}")
    public boolean updateMerchantEva(@PathVariable int id,@PathVariable int star,@PathVariable String evaluate){
        System.out.println("修改评价中,id:"+id);
        boolean evaluates =true;
        evaluates = service.updateMerchantEva(id,star,evaluate);
        System.out.println("修改结束，返回："+evaluates);
        return evaluates;
    }

    @ResponseBody
    @RequestMapping("userevaluate/{userid}/{merchantid}/{star}/{evaluate}")
    public boolean userevaluate(@PathVariable int userid,@PathVariable int merchantid,@PathVariable int star,@PathVariable String evaluate){
        System.out.println("新增评价中,userid:"+userid+"merchantid:"+merchantid+"star:"+star+"evaluate:"+evaluate);
        boolean flg =true;
        flg = service.addEvaluate(userid,merchantid,star,evaluate);
        System.out.println("修改结束，返回："+flg);
        return flg;
    }


    @ResponseBody
    @RequestMapping("findmerchanteva/{searchtext}")
    public ArrayList<evaluate> findMerchantEva(@PathVariable String searchtext){
        System.out.println("搜索评价中:"+searchtext);
        ArrayList<evaluate> evaluates = service.findMerchantEva(searchtext);
        System.out.println("修改结束，返回："+evaluates);
        return evaluates;
    }




}
